package com.fbee.smartcommunities.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.fbee.smartcommunities.entity.Advertising;
import com.fbee.smartcommunities.mapper.AdvertisingMapper;
import com.fbee.smartcommunities.service.AdvertisingService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fbee.smartcommunities.service.UploadFileService;
import io.minio.errors.*;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

/**
 * <p>
 * 轮播图广告表 服务实现类
 * </p>
 *
 * @author 汪佳泉
 * @since 2024-08-18
 */
@Service
public class AdvertisingServiceImpl extends ServiceImpl<AdvertisingMapper, Advertising> implements AdvertisingService {

    @Resource
    private AdvertisingMapper advertisingMapper;

    @Resource
    private UploadFileService uploadFileService;

    @Override
    public Boolean updateImg(Long id, MultipartFile file) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
        String url = uploadFileService.upload("images", file);
        UpdateWrapper<Advertising> advertisingUpdateWrapper = new UpdateWrapper<>();
        advertisingUpdateWrapper.set("url", url).eq("id",id);
        return this.update(advertisingUpdateWrapper);
    }
}
